package com.casework

import org.apache.commons.lang.builder.HashCodeBuilder

class ClassificationProperty implements Serializable{
    Property property
    MeasureClassification classification
    
    boolean equals(other) {
		if (!(other instanceof ClassificationProperty)) {
			return false
		}

		other.property?.id == property?.id &&
			other.classification?.id == classification?.id
	}

	int hashCode() {
		def builder = new HashCodeBuilder()
		if (property) builder.append(property.id)
		if (classification) builder.append(classification.id)
		builder.toHashCode()
	}
    
    static ClassificationProperty get(long propertyId, long classificationId) {
		find 'from ClassificationProperty where property.id=:propertyId and classification.id=:classificationId',
			[propertyId: propertyId, classificationId: classificationId]
	}

	static ClassificationProperty create(Property property, MeasureClassification classification, boolean flush = false) {
		new ClassificationProperty(property: property, classification: classification).save(flush: flush, insert: true)
	}


	static mapping = {
		id composite: ['classification', 'property']
		version false
	}
}
